package com.zjj.spring.javaconfig.config.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import com.zjj.spring.javaconfig.config.bean.ConfigAwareBean;
import com.zjj.spring.javaconfig.config.dto.Bar;
import com.zjj.spring.javaconfig.config.dto.Foo;

@Configuration()
public class AppConfiguration {

	/**
	 * Foo对象构造完毕后，立即调用初始化方法，初始化方法有两种：
	 * 1：@Bean(initMethod="")
	 * 2：@PostConstruct
	 * 销毁对象前调用destroyMethod
	 * */
	@Bean(name = "foo" , initMethod = "initConfig" ,destroyMethod = "destroyConfig")
	@Scope(scopeName = "singleton")
	public Foo foo() {
		return new Foo( bar() );
	}
	
	@Bean(name = "bar")
	@Scope(scopeName = "prototype")
	public Bar bar() {
		return new Bar();
	}
	
	@Bean
	public ConfigAwareBean configAwareBean() {
		return new ConfigAwareBean();
	}
	
}
